/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.member.web;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.persistence.TableSplitResult;
import com.oracleandsxnd.erp.common.web.AjaxResult;
import com.oracleandsxnd.erp.common.web.BaseController;
import com.oracleandsxnd.erp.member.entity.Member;
import com.oracleandsxnd.erp.member.entity.MemberCategory;
import com.oracleandsxnd.erp.member.service.MemberCategoryService;
import com.oracleandsxnd.erp.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员管理Controller
 * @author 会员管理
 * @version 2019-12-13
 */
@Controller
@RequestMapping(value = "member_member")
public class MemberController extends BaseController {

	@Autowired
	private MemberService memberService;

	@Autowired
	private MemberCategoryService memberCategoryService;


	@RequestMapping(value = {""})
	public String list(Model model) {
		List<MemberCategory> memberCategorys= memberCategoryService.findList(new MemberCategory());
		model.addAttribute("memberCategorys",memberCategorys);
		return "erp/member/memberList";
	}
	@RequestMapping(value = {"tjlistData"})
	@ResponseBody
	public Object tjlistData(Member member , HttpServletRequest request, HttpServletResponse response){
		Page page1=new Page<Member>(request, response);
		page1.setOrderBy(" a.integral desc");
		Page<Member> page = memberService.findPage(page1, member);
		TableSplitResult<Member> result=new TableSplitResult<Member>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"listData"})
	@ResponseBody
	public Object listData(Member member , HttpServletRequest request, HttpServletResponse response){
		Page<Member> page = memberService.findPage(new Page<Member>(request, response), member);
		TableSplitResult<Member> result=new TableSplitResult<Member>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"integral"})
	public String integral(Model model) {
		return "erp/member/membertjList";
	}

	@RequestMapping(value = "save")
	@ResponseBody
	public AjaxResult save(Member member) {

		memberService.save(member);
		return success();
	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public AjaxResult  delete(Member member, RedirectAttributes redirectAttributes) {
		memberService.delete(member);
		return success();
	}


}